package com.wanghengzhi.design.patterns.prototype;

import java.util.Hashtable;

class ShapeCache {

    private static final Hashtable<String, Shape> shapeMap = new Hashtable<>();

    public static Shape getType(String id) {
        Shape shape = shapeMap.get(id);
        return (Shape) shape.clone();
    }

    public static void loadCache() {
        Rectangle rectangle = new Rectangle();
        rectangle.setId("1");
        shapeMap.put(rectangle.getId(), rectangle);

        Square square = new Square();
        square.setId("2");
        shapeMap.put(square.getId(), square);

        Circle circle = new Circle();
        circle.setId("3");
        shapeMap.put(circle.getId(), circle);
    }
}
